//package cn.xie.blog.servergateway.service;
//
//import cn.xie.blog.servergateway.mapper.UserMapper;
//import cn.xie.blog.servergateway.ro.User;
//import cn.xie.blog.model.common.entity.login.UserEntity;
//import cn.xie.blog.model.common.enums.login.LoginStatusEnum;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import lombok.RequiredArgsConstructor;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import java.util.Optional;
//
///**
// * @author: xiaoxie
// * create: 2025-04-25 11:44
// * @BelongsProject: blog-parent
// * @BelongsPackage: cn.xie.blog.authcenter.service
// * description:
// */
//@Service
//@RequiredArgsConstructor
//public class UserDetailsServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserDetailsService {
//
//    private final UserMapper userMapper;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        //查询用户
//        UserEntity userEntity = userMapper.selectOne(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUsername, username));
//        if (userEntity == null) {
//            throw new UsernameNotFoundException(username);
//        }
//        User user = new User();
//        user.setId(userEntity.getUserId());
//        user.setUsername(userEntity.getUsername());
//        user.setPassword(userEntity.getPasswordHash());
//        user.setRole(userEntity.getIsAdmin() == 1 ? LoginStatusEnum.ADMIN.getStatus() : LoginStatusEnum.USER.getStatus());
//        user.setEmail(userEntity.getEmail());
//        user.setForbidden(userEntity.getIsDelete() == 1);
//        return Optional.ofNullable(user)
//                .map(u -> org.springframework.security.core.userdetails.User
//                        .withUsername(u.getUsername())
//                        .password(u.getPassword())
//                        .roles(u.getRole())
//                        .build())
//                .orElseThrow(() -> new UsernameNotFoundException(""));
//    }
//
//}
